public class Test {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6,7,8,11,22,33};

       int c= found(arr,5);
        System.out.println("下标"+c+" "+arr[c]);
    }

public static int found(int [] arr,int key) {
    int l = 0;
    int r = arr.length - 1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (arr[mid] == key) {
            return mid;
        } else {
            if (l < r&&arr[mid] < key) {
                l = mid + 1;
            } else if(l < r&&arr[mid] > key){

                r = mid - 1;

            }



        }
    }
    return -1;


}



    public static void sort1(int[] arr)
    {
        int left=0;
        int right=arr.length;
        while(left<right-1){
            while(left<right-1&&arr[left]%2!=0){
                left++;
            }
            while(left<right-1&&arr[right-1]%2==0){
                right--;
            }

            int tem=arr[left];
            arr[left]=arr[right-1];
            arr[right-1]=tem;

        }


    }
    public static void main1(String[] args) {

        int[] arr={1,23,4,5,6,356,8};
//        func1(arr);
        sort1(arr);
        for (int i = 0; i <arr.length ; i++) {
            System.out.print(arr[i]+" ");
        }

    }
    public static void func1(int[] arr)
    {
        for (int i = 0; i <arr.length ; i++) {
            arr[i]*=2;

        }



    }

}
